package app.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import libs.Attendance;
import libs.Student;

/**
 *  Odstraneni aktualne zvoleneho studenta
 * @author Dejvino
 */
public class RemoveStudentAction extends AbstractAction{

    private Attendance attendance;
    private JTree tree = null;

    public RemoveStudentAction(Attendance attendance){
        if(attendance == null)
            throw new NullPointerException("attendance");
        this.attendance = attendance;
    }

    public void setTree(JTree tree){
        if(tree == null)
            throw new NullPointerException("tree");
        this.tree = tree;
    }

    public void actionPerformed(ActionEvent arg0) {
        Student student = (Student)tree.getSelectionPath().getPathComponent(3);
        if(JOptionPane.showConfirmDialog(null,
                java.util.ResourceBundle.getBundle("app/frames/language").getString("ReallyRemoveStudentMSG")+"\n"+student,
                java.util.ResourceBundle.getBundle("app/frames/language").getString("QuestionMSG"),
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0){
            attendance.removeStudent(student);
            tree.getModel().valueForPathChanged(tree.getSelectionPath().getParentPath().getParentPath().getParentPath(), null);
        }
    }
}
